<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="db-queries">
   <title>queries_*</title>
   <body>
      <p>The <codeph>queries_*</codeph> tables store high-level query status information.</p>
      <p>The <codeph>tmid</codeph>, <codeph>ssid</codeph> and <codeph>ccnt</codeph> columns are the
         composite key that uniquely identifies a particular query.</p>
      <p>There are three queries tables, all having the same columns:</p>
      <ul>
         <li>
            <codeph>queries_now</codeph> is an external table whose data files are stored in
               <codeph>$MASTER_DATA_DIRECTORY/gpperfmon/data</codeph>. Current query status is
            stored in <codeph>queries_now</codeph> during the period between data collection from
            the <codeph>gpperfmon</codeph> agents and automatic commitment to the
               <codeph>queries_history</codeph> table.</li>
         <li>
            <codeph>queries_tail</codeph> is an external table whose data files are stored in
               <codeph>$MASTER_DATA_DIRECTORY/gpperfmon/data</codeph>. This is a transitional table
            for query status data that has been cleared from <codeph>queries_now</codeph> but has
            not yet been committed to <codeph>queries_history</codeph>. It typically only contains a
            few minutes worth of data.</li>
         <li>
            <codeph>queries_history</codeph> is a regular table that stores historical query status
            data. It is pre-partitioned into monthly partitions. Partitions are automatically added
            in two month increments as needed. </li>
      </ul>
      <table>
         <tgroup cols="2">
            <thead>
               <row>
                  <entry>Column</entry>
                  <entry>Type</entry>
                  <entry>Description</entry>
               </row>
            </thead>
            <tbody>
               <row>
                  <entry>
                     <codeph>ctime</codeph>
                  </entry>
                  <entry>timestamp</entry>
                  <entry>Time this row was created.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>tmid</codeph>
                  </entry>
                  <entry>int</entry>
                  <entry>A time identifier for a particular query. All records associated with the
                     query will have the same <codeph>tmid</codeph>.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>ssid</codeph>
                  </entry>
                  <entry>int</entry>
                  <entry>The session id as shown by <codeph>gp_session_id</codeph>. All records
                     associated with the query will have the same <codeph>ssid</codeph>.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>ccnt</codeph>
                  </entry>
                  <entry>int</entry>
                  <entry>The command number within this session as shown by
                        <codeph>gp_command_count</codeph>. All records associated with the query
                     will have the same <codeph>ccnt</codeph>.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>username</codeph>
                  </entry>
                  <entry>varchar(64)</entry>
                  <entry>Greenplum role name that issued this query.</entry>
               </row>
               <row>
                  <entry>
                     <p>
                        <codeph>db</codeph>
                     </p>
                  </entry>
                  <entry>varchar(64)</entry>
                  <entry>Name of the database queried.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>cost</codeph>
                  </entry>
                  <entry>int</entry>
                  <entry>Not implemented in this release.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>tsubmit</codeph>
                  </entry>
                  <entry>timestamp</entry>
                  <entry>Time the query was submitted.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>tstart</codeph>
                  </entry>
                  <entry>timestamp</entry>
                  <entry>Time the query was started.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>tfinish</codeph>
                  </entry>
                  <entry>timestamp</entry>
                  <entry>Time the query finished.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>status</codeph>
                  </entry>
                  <entry>varchar(64)</entry>
                  <entry>Status of the query -- <codeph>start</codeph>, <codeph>done</codeph>, or
                        <codeph>abort</codeph>.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>rows_out</codeph>
                  </entry>
                  <entry>bigint</entry>
                  <entry>Rows out for the query.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>cpu_elapsed</codeph>
                  </entry>
                  <entry>bigint</entry>
                  <entry>
                     <p>CPU usage by all processes across all segments executing this query (in
                        seconds). It is the sum of the CPU usage values taken from all active
                        primary segments in the database system.</p>
                     <p>Note that the value is logged as 0 if the query runtime is shorter than the
                        value for the quantum. This occurs even if the query runtime is greater than
                        the value for <codeph>min_query_time</codeph>, and this value is lower than
                        the value for the quantum.</p>
                  </entry>
               </row>
               <row>
                  <entry>
                     <codeph>cpu_currpct</codeph>
                  </entry>
                  <entry>float</entry>
                  <entry>
                     <p>Current CPU percent average for all processes executing this query. The
                        percentages for all processes running on each segment are averaged, and then
                        the average of all those values is calculated to render this metric.</p>
                     <p>Current CPU percent average is always zero in historical and tail data.</p>
                  </entry>
               </row>
               <row>
                  <entry>
                     <codeph>skew_cpu</codeph>
                  </entry>
                  <entry>float</entry>
                  <entry>
                     <p>Displays the amount of processing skew in the system for this query.
                        Processing/CPU skew occurs when one segment performs a disproportionate
                        amount of processing for a query. This value is the coefficient of variation
                        in the CPU% metric across all segments for this query, multiplied by 100.
                        For example, a value of .95 is shown as 95.</p>
                  </entry>
               </row>
               <row>
                  <entry>
                     <codeph>skew_rows</codeph>
                  </entry>
                  <entry>float</entry>
                  <entry>Displays the amount of row skew in the system. Row skew occurs when one
                     segment produces a disproportionate number of rows for a query. This value is
                     the coefficient of variation for the <codeph>rows_in</codeph> metric across all
                     segments for this query, multiplied by 100. For example, a value of .95 is
                     shown as 95.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>query_hash</codeph>
                  </entry>
                  <entry>bigint</entry>
                  <entry>Not implemented in this release.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>query_text</codeph>
                  </entry>
                  <entry>text</entry>
                  <entry>The SQL text of this query.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>query_plan</codeph>
                  </entry>
                  <entry>text</entry>
                  <entry>Text of the query plan. Not implemented in this release.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>application_name</codeph>
                  </entry>
                  <entry>varchar(64)</entry>
                  <entry>The name of the application.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>rsqname</codeph>
                  </entry>
                  <entry>varchar(64)</entry>
                  <entry>If the resource queue-based resource management scheme is active,
                     this column specifies the name of the resource queue.</entry>
               </row>
               <row>
                  <entry>
                     <codeph>rqppriority</codeph>
                  </entry>
                  <entry>varchar(64)</entry>
                  <entry>If the resource queue-based resource management scheme is active,
                     this column specifies the priority of the query -- <codeph>max, high, med, low, or
                     min</codeph>.</entry>
               </row>
            </tbody>
         </tgroup>
      </table>
   </body>
</topic>
